package cn.com.nes.site.entity.em.crm.customer;

import cn.com.nes.common.exception.NoSuchEnumException;
import cn.com.nes.site.entity.em.IEnum;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 能源类型 枚举
 *  值域对应 t_param 表 param_type=323
 */
@Slf4j
@Getter
public enum EnergyTypeEnum implements IEnum<String> {

    _0("0","煤改电"),
    _1("1","煤改气"),
    _2("2","生物质"),
    _3("3","清洁煤"),
    ;

    private final String key;

    private final String value;

    EnergyTypeEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public static EnergyTypeEnum getEnum(String key) {
        Map<String, EnergyTypeEnum> map = new HashMap<>();
        for (EnergyTypeEnum energyTypeEnum : values()) {
            map.put(energyTypeEnum.getKey(), energyTypeEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的能源类型");
        }
        return map.get(key);
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getValue();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }
}
